﻿using System;
using System.Collections.Generic;
using System.Text;
using Model;

namespace Aliyeye.Car.Net.UI.Common
{
    public class UserCommon
    {
        public static string GetCurrentUser()
        {
            CurrentUser currentUser = CurrentUser.GetInstance();
            if (currentUser.IsLogin)
                return currentUser.UserName;
            return null;
        }

        public static Int32 GetCurrentUserID()
        {
            CurrentUser currentUser = CurrentUser.GetInstance();
            if (currentUser.IsLogin)
                return currentUser.info.UserID;
            return 0;
        }

        public static void UserLogin(Accounts_Users info, string userName)
        {
            CurrentUser currentUser = CurrentUser.GetInstance();
            currentUser.IsLogin = true;
            currentUser.info = info;
            currentUser.UserName = userName;
        }

        public static void UserLogout()
        {
            CurrentUser currentUser = CurrentUser.GetInstance();
            currentUser.IsLogin = false;
            currentUser.UserName = null;
            currentUser.info = null;
        }
    }

    /// <summary>
    /// Current Login User Information
    /// </summary>
    public sealed class CurrentUser
    {
        public static readonly CurrentUser _instance = new CurrentUser();

        public bool IsLogin;
        public string UserName;
        public Accounts_Users info;

        private CurrentUser()
        {
            IsLogin = false;
            UserName = null;
        }

        public static CurrentUser GetInstance()
        {
            if (null != _instance)
                return _instance;
            return new CurrentUser();
        }
    }
}
